<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>3D转换</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }
        li {
            list-style: none;
        }
        body {
            /* 透视写在被观察元素的父盒子上 */
            perspective: 500px;
        }
        .no3d { 
            margin: 0 auto;
            width: 50px;
            height: 50px;
            background-color: coral;
        }
        .trans3d {
            margin: 0 auto;
            width: 50px;
            height: 50px;
            background-color: #666;
            /* xyz不能省略 没有写0 z有透视才能看到效果 */
            transform: translate3d(50px, 50px, 130px);
        }
        div[class^="rotate"] {
            float: left;
            height: 100px;
            width: 100px;
            background-color: cornflowerblue;
            margin: 20px;
            transition: all 2s;
            text-align: center;
            line-height: 100px;
            color: #fff;
        }
        .rotate-x:hover {
            /* 左手准则 拇指指向x轴方向 */
            transform: rotateX(45deg);
        }
        .rotate-y:hover {
            /* 左手准则 拇指指向y轴方向 */
            transform: rotateY(45deg);
        }
        .rotate-z:hover {
            /* 和2d的rotate基本一样 */
            transform: rotateZ(45deg);
        }
        .rotate-xyz:hover {
            transform: rotate3d(1, 1, 1, 45deg);
        }
        .cx {
            width: 200px;
            height: 200px;
            margin: 50px auto;
            perspective: 500px;
        }
        .chengxian {
            position: relative;
            width: 100px;
            height: 100px;
            transition: all 2s;
            /* 让子元素开启3D立体环境 */
            transform-style: preserve-3d;
        }
        .chengxian:hover {
            transform: rotateY(60deg);
        }
        .cheng,
        .xian  {
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
        }
        .cheng {
            background-color: crimson;
        }
        .xian {
            background-color: darkkhaki;
            transform: rotateX(60deg);
        }

        /* 案例1 */
        .box1 {
            position: relative;
            width: 100px;
            height: 100px;
            margin: 0 auto;
            transition: all 1s;
            transform-style: preserve-3d;
        }
        .box1:hover {
            transform: rotateY(-180deg);
        }
        .front1,
        .back1 {
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            border-radius: 50%;
            text-align: center;
            line-height: 100px;
            color: #fff;
        }
        .front1 {
            background-color: darksalmon;
            z-index: 1;
        }
        .back1 {
            background-color: darkseagreen;
            transform: rotateY(180deg);
        }

        /* 案例2 */
        .anli2 {
            width: 800px;
            height: 100px;
        }
        ul {
            margin: 50px;
        }
        ul li {
            float: left;
            width: 120px;
            height: 35px;
            margin: 0 5px;
            perspective: 500px;
        }
        .box2 {
            position: relative;
            width: 100%;
            height: 100%;
            transition: all .5s;
            transform-style: preserve-3d;
        }
        .box2:hover {
            transform: rotateX(90deg);
        }
        .front2,
        .bottom {
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            text-align: center;
            line-height: 35px;
            color: #fff;
        }
        .front2 {
            background-color: deeppink;
            z-index: 1;
            transform: translateZ(17.5px);
        }
        .bottom {
            background-color: deepskyblue;
            /* 要先写移动 */
            transform: translateY(17.5px) rotateX(-90deg);
        }
    </style>
</head>
<body>
    <!-- 3D位移 -->
    <div class="no3d"></div>
    <div class="trans3d"></div>

    <!-- 3D旋转 -->
    <div class="rotate-x">你</div>
    <div class="rotate-y">好</div>
    <div class="rotate-z">骚</div>
    <div class="rotate-xyz">啊</div>

    <!-- 3D呈现transform-style -->
    <div class="cx">
        <div class="chengxian">
            <div class="cheng"></div>
            <div class="xian"></div>
        </div>
    </div>
        
    <!-- 案例 -->
    <!-- 1 -->
    <div class="box1">
        <div class="front1">哈喽哈喽</div>
        <div class="back1">我是mm</div>
    </div>

    <!-- 2 -->
    <div class="anli2">
        <ul>
            <li>
                <div class="box2">
                    <div class="front2">耶嘿！</div>
                    <div class="bottom">哦吼啦~</div>
                </div>
            </li>
            <li>
                <div class="box2">
                    <div class="front2">耶嘿！</div>
                    <div class="bottom">哦吼啦~</div>
                </div>
            </li>
            <li>
                <div class="box2">
                    <div class="front2">耶嘿！</div>
                    <div class="bottom">哦吼啦~</div>
                </div>
            </li>
            <li>
                <div class="box2">
                    <div class="front2">耶嘿！</div>
                    <div class="bottom">哦吼啦~</div>
                </div>
            </li>
            <li>
                <div class="box2">
                    <div class="front2">耶嘿！</div>
                    <div class="bottom">哦吼啦~</div>
                </div>
            </li>
        </ul>
    </div>
</body>
</html>